package com.biz.primus.ms.order.convertor;

import com.biz.primus.model.order.vo.aftersale.ReturnOrderItemRequestVO;
import com.biz.primus.model.order.vo.aftersale.ReturnOrderItemResponseVO;
import com.biz.primus.ms.order.dao.po.OrderItem;
import com.biz.primus.ms.order.dao.po.ReturnOrder;
import com.biz.primus.ms.order.dao.po.ReturnOrderItem;
import org.codelogger.utils.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 退货单商品项转换器
 *
 * @author Tiger Feng
 * @date 2017年11月20日
 */
public class ReturnOrderItemConvertor {

    public static ReturnOrderItem reqVO2PO(ReturnOrderItemRequestVO vo, ReturnOrder returnOrder) {
        if (vo == null) {
            return null;
        }
        ReturnOrderItem po = new ReturnOrderItem();
        BeanUtils.copyProperties(vo, po);
        po.setReturnOrder(returnOrder);
        return po;
    }

    public static List<ReturnOrderItem> reqVOs2POs(List<ReturnOrderItemRequestVO> vos, ReturnOrder returnOrder) {
        if (vos == null || vos.isEmpty()) {
            return new ArrayList<>();
        }
        return vos.stream()
                .map(returnOrderItemRequestVO -> reqVO2PO(returnOrderItemRequestVO, returnOrder))
                .collect(Collectors.toList());
    }

    public static ReturnOrderItemResponseVO po2RespVO(ReturnOrderItem po) {
        if (po == null) {
            return null;
        }
        ReturnOrderItemResponseVO vo = new ReturnOrderItemResponseVO();
        BeanUtils.copyProperties(po, vo);
        OrderItem orderItem = po.getOrderItem();
        if (po != null) {
            vo.setBrandId(orderItem.getBrandId());
            vo.setCategoryId(orderItem.getCategoryId());
            vo.setFinalPrice(orderItem.getFinalPrice());
            vo.setLogo(orderItem.getLogo());
            vo.setPackageNumber(orderItem.getPackageNumber());
            vo.setWeight(orderItem.getWeight());
        }
        return vo;
    }

    public static List<ReturnOrderItemResponseVO> pos2RespVOs(List<ReturnOrderItem> pos) {
        if (pos == null || pos.isEmpty()) {
            return new ArrayList<>();
        }
        return pos.stream()
                .map(returnOrderItem -> po2RespVO(returnOrderItem))
                .collect(Collectors.toList());
    }

}
